package com.longling.hayarider.callback;

import com.google.gson.internal.$Gson$Types;
import com.longling.hayarider.entity.BaseEntity;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import okhttp3.Request;

/**
 * @ClassName OKHttpCallBack
 * @Description TODO
 * @date 2021-08-23 19:38
 * @Company LongLing
 * @Version 1.0
 * @Author 潇妙
 */
public abstract class OKHttpCallBack<T> {

    public static Type mType;
    public OKHttpCallBack(){
        mType=getSuperclassTypeParameter(getClass());
    }
    static Type getSuperclassTypeParameter(Class<?> subclass){
        Type superclass = subclass.getSuperclass();
        if (superclass instanceof Class){
            throw new RuntimeException("Missing type parameter.");
        }
        ParameterizedType parameterizedType = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterizedType.getActualTypeArguments()[0]);
    }
    public void onBefore(Request request){

    }

    public void onAfter(){

    }
    public abstract void onSuccess(T response);
    public abstract void onFailure(BaseEntity<T> entity, String message);
}
